﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
using Bussiness;

namespace GUI
{
    public partial class frmThamSo : Form
    {
        public frmThamSo()
        {
            InitializeComponent();
        }

        private void btnExit_Click(object sender, EventArgs e) {
            Close();
        }

        private void frmThamSo_Load(object sender, EventArgs e) {
            //load thong tin len dgv
            idColumn.DataPropertyName = ThamSoColumn.IDThamSo;
            tenThamSoColumn.DataPropertyName = ThamSoColumn.TenThamSo;
            dienGiaiColumn.DataPropertyName = ThamSoColumn.DienGiai;
            quyDinhColumn.DataPropertyName = ThamSoColumn.QuyDinh;
            suDungColumn.DataPropertyName = ThamSoColumn.SuDung;

            ThamSoService service = new ThamSoService();
            dgvThamSo.DataSource = service.GetThamSoList();

            for (int i = 0; i < dgvThamSo.RowCount; i++)
                dgvThamSo.Rows[i].Cells[0].Value = i + 1;
        }

        private void btnCapNhat_Click(object sender, EventArgs e) {
            List<ThamSoDTO> thamSoList = new List<ThamSoDTO>();
            for (int i = 0; i < dgvThamSo.RowCount; i++) {
                ThamSoDTO ts = new ThamSoDTO();
                ts.IDThamSo = Convert.ToInt32( dgvThamSo.Rows[i].Cells["idColumn"].Value);
                ts.QuyDinh = Convert.ToInt32(dgvThamSo.Rows[i].Cells["quyDinhColumn"].Value);
                ts.DienGiai = dgvThamSo.Rows[i].Cells["dienGiaiColumn"].Value.ToString();

                thamSoList.Add(ts);
            }

            ThamSoService service = new ThamSoService();
            if (service.UpdateThamSo(thamSoList))
                MessageBox.Show("Cập nhật thành công");
            else
                MessageBox.Show("Có lỗi, vui lòng thử lại");
        }


    }
}
